<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html>
<html>
<head>
	<title>消息管理</title>
    <%@ include file="/common/import.jsp" %>
	<script type="text/javascript">
		$(function(){
			$('#timeTaskList').datagrid({
				title:'消息列表',
				url:'${ctx }/send/sendmsg/list',
				striped : true,
				collapsible : true,
				pagination : true,
				singleSelect : true,
				nowrap: true,//数据长度超出列宽时将会自动截取。
				rownumbers:true,//行号
				fitColumns:true,//自动使列适应表格宽度以防止出现水平滚动
				remoteSort: false,
				idField:'msgId',
				columns:[[
                    {field:'msgTitle',title:'标的',width:200,align : 'center',sortable:true},
					{field:'msgType',title:'类型',width:80,align : 'center',sortable:true,
                    	formatter:function(value){
                    		if("email"==value){return "邮件";}
                    		else if("mobile"==value){return "手机";}
                    		else if("all"==value){return "邮件+手机";}
                    	}
                    },
					{field:'fromUserName',title:'发送人',width:100,align : 'center',sortable:true},
					{field:'toUserName',title:'接收人',width:100,align : 'center',sortable:true},
					{field:'msgSendTime',title:'发送时间',width:120,align : 'center',sortable:true},
					{field:'sysEname',title:'来源',width:100,align : 'center',sortable:true},
					{field:'msgStatus',title:'状态',width:100,align : 'center',sortable:true,
						formatter:function(value,rowData){
							if( value=="0"){
								if(rowData.msgPassNum !='0'){
									return '<font color=red>发送失败</font><br>失败次数：'+rowData.msgPassNum;
								}else{
									return '等待发送';
								}
							}else if(value=="1"){
								return '<font color=block>发送成功</font>';
							}else{ return '<font color=red>发送失败</font>';}
						}
					}
				]],
				toolbar:[{
					text:'删除',
					iconCls:'icon-remove',
					handler:function(){
						deleteCate();
					}
				},'-',{
					text:'修改',
					iconCls:'icon-edit',
					handler:function(){
						editCate();
					}
				}
				]	
			});		
		});
		
		// 点击取消按钮，关闭添加窗口
		function colseAdd(){
			$('#saveDiv').window('close');
		}
		// 刷新列表
		function cateReload(){
			$('#timeTaskList').datagrid('reload');
		}
		// 判断是否选中一条记录
		function getSelected(){
			var selected = $('#timeTaskList').datagrid('getSelected');
			if (selected){
				return selected;
			}else{
				$.messager.alert('提示', '请选择要操作的数据', 'info');
			}
		}
		
		// 进入修改页面
		function editCate(){
			var node = getSelected();		
			if (node){	
				var url = '${ctx}/send/sendmsg/view/'+node.msgId;
				$('#saveDiv').attr("title",node.msgTitle);
				$('#saveFrame').attr("src",url);
				$('#saveDiv').window('open');
			}
		}
		
		//删除，物理删除
		function deleteCate(){					
			var node = getSelected();	
			if(node){
		    	$.messager.confirm('确认','您确定要删除:<font color=red>'+node.msgTitle+'</font> ？',function(r){
		        	if(r){
						$.ajax({
							type: "delete",
							url: "${ctx}/send/sendmsg/msg/"+node.msgId,
							dataType: "json",
							success: function(data){
								var result = data;//jQuery.parseJSON(data);
	    						if(result.flag=='T'){
									$.messager.alert('结果', '操作成功', 'info');	
								    var rowIndex = $('#timeTaskList').datagrid('getRowIndex',node);								
								    $('#timeTaskList').datagrid('deleteRow', rowIndex);	
	    						}else {
	    							$.messager.alert('结果', result.msg, 'info');	
	    						}
							},
							error:function(messg)  { 
					       	    $.messager.alert('错误提示', '操作失败:'+messg.responseText, 'error');
					       } 
						});
		          	}
		       });		             		
		    }	
		}

	</script>
</head>
<body class="home-template">
	<table id="timeTaskList"></table>
	
	<!-- 添加窗口 -->
	<div id="saveDiv" class="easyui-window" title="修改消息信息" style="padding:5px;width: 580px; height:350px; overflow: hidden;"
    	iconCls="icon-search" closed="true" maximizable="false" minimizable="false" collapsible="false">
   		<iframe frameborder="0"  id="saveFrame" height="100%" width="99%" scrolling="yes" frameborder="0" ></iframe>
    </div>
    <%@ include file="/common/top.jsp" %>
</body>
</html>